<?php

class excel extends Model {
    function __construct() {
        parent::__construct();
    }
    function makeExcel($header, &$data, $filename) {
        @ob_end_clean();
        $str = '';
//        header('Content-Type: application/pdf');
//        header('Content-Disposition: attachment;filename="01simple.pdf"');
        header("Content-type:application/vnd.ms-excel;charset:GBK");
        header("Content-disposition: attachment; filename=$filename.xls");
        header('Cache-Control: max-age=0');
        foreach($header as $value) {
            $str .= mb_convert_encoding($value."\t",'GBK','UTF-8');
        }
        $str .= "\n";
        $head_key = array_keys($header);

        foreach($data as $value) {
            foreach($head_key as $filed) {
                if($pos = strpos($filed, '.')) {
                    $f = substr($filed, 0, $pos);
                    $k = substr($filed, $pos+1);
                    if(isset($value[$f]) && isset($value[$f][$k]))
                        $str .= str_replace(array("\n","\r","\t"),"",mb_convert_encoding($value[$f][$k],'GBK','UTF-8'));
                } else {
                    if(isset($value[$filed]))
                        $str .= str_replace(array("\n","\r","\t"),"",mb_convert_encoding($value[$filed],'GBK','UTF-8'));
                }
                $str .= "\t";
            }
            $str .= "\n";
        }
        echo $str;
        unset($data);
        unset($str);
        exit;
    }
}
?>